package models

import (
	"gorm.io/gorm"
	"order_srv/basic/config"
	"time"
)

// CouponShares 优惠券分享表
type CouponShares struct {
	Id          uint64         `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	CouponId    uint64         `gorm:"column:coupon_id;type:bigint UNSIGNED;comment:优惠券id;not null;" json:"coupon_id"`                     // 优惠券id
	ShareBy     uint64         `gorm:"column:share_by;type:bigint UNSIGNED;comment:分享者用户id;not null;" json:"share_by"`                     // 分享者用户id
	ReceiveBy   uint64         `gorm:"column:receive_by;type:bigint UNSIGNED;comment:领取者用户id;default:NULL;" json:"receive_by"`             // 领取者用户id
	ShareTime   time.Time      `gorm:"column:share_time;type:datetime;comment:分享时间;not null;default:CURRENT_TIMESTAMP;" json:"share_time"` // 分享时间
	ReceiveTime time.Time      `gorm:"column:receive_time;type:datetime;comment:领取时间;default:CURRENT_TIMESTAMP;" json:"receive_time"`      // 领取时间
	CreatedAt   time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt   time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt   gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (cs *CouponShares) TableName() string {
	return "coupon_shares"
}

// CouponSharesAdd 添加优惠券分享
func (cs *CouponShares) CouponSharesAdd() error {
	return config.DB.Create(&cs).Error
}
